package com.flower.sequence.parse;

import com.flower.sequence.segment.DateSegmentGenerator;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.w3c.dom.Element;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * @author shanks on 2019-10-12
 */

public class DateSegmentDefinitionParse extends AbstractSingleBeanDefinitionParser {

    @Override
    protected Class<?> getBeanClass(Element element) {
        return DateSegmentGenerator.class;
    }

    @Override
    protected void doParse(Element element, BeanDefinitionBuilder builder) {
        String pattern = element.getAttribute("pattern");
        String length = element.getAttribute("length");
        builder.addPropertyValue("currentDate", LocalDateTime.now());
        builder.addPropertyValue("pattern", pattern);
        builder.addPropertyValue("length", length);
    }
}
